package cyz.text.textactivity;



import androidx.annotation.NonNull;

import org.junit.Test;

import cyz.text.textactivity.core.handler.CyzHandler;
import cyz.text.textactivity.core.handler.CyzLooper;
import cyz.text.textactivity.core.handler.CyzMessage;

/**
 * 手写handler test文件夹下的 test.java.cyz.text.textactivity.DNActivityThread
 */
public class DNActivityThread {
    @Test
    public void main(){
        //创建全程唯一的主线程looper对象
        CyzLooper.prepare(false);
        //创建Handler对象
        final CyzHandler cyzHandler = new CyzHandler(){
            @Override
            public void handleMessage(@NonNull CyzMessage msg) {
                super.handleMessage(msg);
                //获取发送消息
                System.out.println(msg.obj.toString());
            }
        };

        new Thread(new Runnable() {
            @Override
            public void run() {
                CyzMessage message = new CyzMessage();
                message.what = 1;
                message.obj = "大家晚上好";
                cyzHandler.sendMessage(message);
            }
        }).start();

        //获取消息
        CyzLooper.loop();
    }
}
